package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.model.MistakeBookModel;
import com.example.hyw.szysteam.view.ReviewActivity;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/7/11.
 */

public class SaveMistakeBookPresenter {
    MistakeBookModel mistakeBookModel=new MistakeBookModel();
    ReviewActivity reviewActivity;

    public SaveMistakeBookPresenter(ReviewActivity reviewActivity) {
        this.reviewActivity = reviewActivity;
    }

    public void saveMistakeBook(String email,int id,String myanswer){
        mistakeBookModel.saveMistakeBook(email, id,myanswer)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<Integer>>() {
                    @Override
                    public void accept(HttpResult<Integer> integerHttpResult) throws Exception {
                        if (integerHttpResult.getResult()==1) {
                            reviewActivity.success1();
                        }else {
                            reviewActivity.error();
                        }
                    }
                });
    }

    public void saveMistakeBooks(String email,String list,String myanswer){
        mistakeBookModel.saveMistakeBooks(email, list,myanswer)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<Integer>>() {
                    @Override
                    public void accept(HttpResult<Integer> integerHttpResult) throws Exception {
                        int i=integerHttpResult.getContent();
                        if (i>0) {
                            reviewActivity.success2(i);
                        }else {
                            reviewActivity.error2();
                        }
                    }
                });
    }
}
